<template>
  <a-modal title="商品选择" width="850px" :zIndex="2000" :visible="visible" :confirmLoading="loading" @ok="handleSubmit" @cancel="handleCancel">
    <f-table ref="table" rowKey="drugsId" v-if="visible" @dblclick="dblclick" :columns="columns" :multiple="false" :showRadio="true" :params="queryParam" :api="api.drugs" @onSelectChange="onSelectChange">
    </f-table>
  </a-modal>
</template>
<script>
  import api from './js/api'

  export default {
    name: 'SelectDrugsModal',
    props: {},
    data() {
      return {
        refs: this.$refs,
        api: Object.assign(api, this.api),
        loading: false,
        visible: false,
        selectedRowKeys: [],
        selectedRows: [],
        //列表初始化查询参数
        queryParam: {},
        // 表头
        columns: [
          {
            title: '商品名称',
            align: 'center',
            dataIndex: 'drugsName'
          },
          {
            title: '商品规格',
            align: 'center',
            dataIndex: 'drugsSpec'
          },
          {
            title: '自营',
            align: 'center',
            dataIndex: 'ownerState'
          },
          {
            title: '供应商',
            align: 'center',
            dataIndex: 'supplierName'
          }
        ]
      }
    },
    methods: {
      open(supplierId) {
        if (supplierId) {
          this.queryParam.supplierId = supplierId
        }
        this.visible = true
        this.selectedRowKeys = []
        this.selectedRows = []
      },
      close() {
        this.$emit('close')
        this.visible = false
      },
      dblclick(record,event){
        let selectedRowKeys=[];
        let selectedRows=[];
        selectedRowKeys.push(record.drugsId);
        selectedRows.push(record);
        this.$emit('drugsSelectChange', selectedRowKeys, selectedRows)
        this.close()
      },
      handleCancel() {
        this.close()
      },
      handleSubmit() {
        this.$emit('drugsSelectChange', this.selectedRowKeys, this.selectedRows)
        this.close()
      },
      onSelectChange(selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      }
    },
    created() {
    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
